package com.mistyrain.controller;

import com.mistyrain.entity.Menu;
import com.mistyrain.entity.MenuVO;
import com.mistyrain.entity.Type;
import com.mistyrain.service.MenuService;
import com.mistyrain.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuHandler {
    @Autowired
    private MenuService menuService;
    @Autowired
    private TypeService typeService;

    @GetMapping("/findAll/{page}/{limit}")
    @ResponseBody
    public MenuVO findAll(@PathVariable("page") int page, @PathVariable("limit") int limit){
        return menuService.findAll(page, limit);
    }

    @GetMapping("/findAll")
    public List<Type> findAll(){
        return typeService.findAll();
    }

    @PostMapping("/save")
    public void save(@RequestBody Menu menu){
        menuService.save(menu);
    }

    @GetMapping("/findById/{id}")
    public Menu findById(@PathVariable("id") long id){
        return menuService.findById(id);
    }

    @PutMapping("/update")
    public void update(@RequestBody Menu menu){
        menuService.update(menu);
    }

    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable("id") long id){
        menuService.deleteById(id);
    }
}
